import {
  getPermissionTable,
  insertOnePermission,
  deletePermissions,
} from "@/api/permission";
import {getToken} from "@/utils/auth";

const getDefaultState = () => {
  return {
    token: getToken(),
    name: "",
    avatar: "",
  };
};

const state = getDefaultState();

const actions = {
  //获取权限列表
  getPermissionTable({commit}, per) {
    return new Promise((resolve, reject) => {
      getPermissionTable(per)
        .then((response) => {
          resolve(response);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  //获取权限列表
  insertOnePermission({commit}, per) {
    return new Promise((resolve, reject) => {
      insertOnePermission(per)
        .then((response) => {
          resolve(response);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
  //批量删除权限
  deletePermissions({commit}, ids) {
    return new Promise((resolve, reject) => {
      deletePermissions(ids)
        .then((response) => {
          resolve(response);
        })
        .catch((error) => {
          reject(error);
        });
    });
  },
};

export default {
  namespaced: true,
  state,
  actions,
};
